options.js ➔ ???   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 49
rs 8.669
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A options.js ➔ ... ➔ ??? 0 3 1
1
/** global: browser */
2
/** global: Wappalyzer */
3
4
const wappalyzer = new Wappalyzer();
5
6
function getOption(name, defaultValue, callback) {
7
  browser.storage.local.get(name)
8
    .then(item => {
9
      callback(item.hasOwnProperty(name) ? item[name] : defaultValue);
10
    });
11
}
12
13
function setOption(name, value) {
14
  ( chrome || browser ).runtime.sendMessage({
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable chrome is declared in the current environment, consider using typeof chrome === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
15
    id: 'set_option',
16
    key: name,
17
    value: value
18
  });
19
}
20
21
document.addEventListener('DOMContentLoaded', () => {
22
  var nodes = document.querySelectorAll('[data-i18n]');
23
24
  Array.prototype.forEach.call(nodes, node => {
25
    node.childNodes[0].nodeValue = browser.i18n.getMessage(node.dataset.i18n);
26
  });
27
28
  document.querySelector('#github').addEventListener('click', () => {
29
    open(wappalyzer.config.githubURL);
30
  });
31
32
  document.querySelector('#twitter').addEventListener('click', () => {
33
    open(wappalyzer.config.twitterURL);
34
  });
35
36
  document.querySelector('#wappalyzer').addEventListener('click', () => {
37
    open(wappalyzer.config.websiteURL);
38
  });
39
40
  getOption('upgradeMessage', true, value => {
41
    const el = document.querySelector('#option-upgrade-message');
42
43
    el.checked = value;
44
45
    el.addEventListener('change', () => {
46
      setOption('upgradeMessage', el.checked);
47
    });
48
  });
49
50
  getOption('dynamicIcon', true, value => {
51
    const el = document.querySelector('#option-dynamic-icon');
52
53
    el.checked = value;
54
55
    el.addEventListener('change', () => {
56
      setOption('dynamicIcon', el.checked);
57
    });
58
  });
59
60
  getOption('tracking', true, value => {
61
    const el = document.querySelector('#option-tracking');
62
63
    el.checked = value;
64
65
    el.addEventListener('change', () => {
66
      setOption('tracking', el.checked);
67
    });
68
  });
69
});
70